package com.ynet.middleground.user.service.impl;

import com.google.common.base.Throwables;
import com.ynet.core.common.BaseReqObj;
import com.ynet.core.common.ServiceResult;
import com.ynet.core.exception.BusinessException;
import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.user.bean.AddUserRoleRelationReq;
import com.ynet.middleground.user.bean.DeleteAddUserRoleRelationReq;
import com.ynet.middleground.user.bean.QueryUserRoleRelationListReq;
import com.ynet.middleground.user.bean.QueryUserRoleRelationReq;
import com.ynet.middleground.user.common.ErrorMessageConstant;
import com.ynet.middleground.user.dto.*;
import com.ynet.middleground.user.model.UserRoleRelationModel;
import com.ynet.middleground.user.service.UserRoleRelationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 * <p>
 * 企业员工用户角色关系 服务实现类
 * </p>
 *
 * @author Wangxz
 * @since 2019-11-05
 */
@Path("userRoleRelationService")
@Produces({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8", MediaType.TEXT_XML + "; " + "charset=UTF-8"})
@Api(value = "企业员工用户角色关系", tags = {"企业员工用户角色关系接口"})
@Service(timeout = 6000, version = "0.0.1")
public class UserRoleRelationServiceImpl implements UserRoleRelationService, GenericService {

    @Autowired
    private UserRoleRelationModel userRoleRelationModel;

    /**
     * 员工角色关系添加
     * 
     * @param addUserRoleRelationReq
     * @return
     */
    @POST
    @Path("add-user-role-relation")
    @ApiOperation(value = "企业员工角色关系添加", notes = "企业员工角色关系添加")
    @Override
    public ServiceResult<String> addUserRoleRelation(AddUserRoleRelationReq addUserRoleRelationReq) {
        ServiceResult<String> serviceResult = new ServiceResult<>();
        try {
            userRoleRelationModel.addUserRoleRelation(addUserRoleRelationReq);
        } catch (BusinessException be) {
            IfpLogger.error("addEnterpriseUserInfo", "业务逻辑异常,case:{}", Throwables.getStackTraceAsString(be));
            serviceResult.setError(be.getCode(), be.getMessage());
            return serviceResult;
        } catch (Exception e) {
            IfpLogger.error("addEnterpriseUserInfo", "执行添加企业员工用户异常,case:{}", Throwables.getStackTraceAsString(e));
            serviceResult.setError(ErrorMessageConstant.ECUC0000_CODE, ErrorMessageConstant.ECUC0000_MESSAGE);
            return serviceResult;
        }
        return serviceResult;
    }

    /**
     * 员工角色关系删除
     * 
     * @param deleteAddUserRoleRelationReq
     * @return
     */
    @POST
    @Path("delete-user-role-relation")
    @ApiOperation(value = "企业员工角色关系删除", notes = "企业员工角色关系删除")
    @Override
    public ServiceResult<String> deleteUserRoleRelation(DeleteAddUserRoleRelationReq deleteAddUserRoleRelationReq) {
        ServiceResult<String> serviceResult = new ServiceResult<>();
        try {
            userRoleRelationModel.deleteUserRoleRelation(deleteAddUserRoleRelationReq);
        } catch (BusinessException be) {
            IfpLogger.error("addEnterpriseUserInfo", "业务逻辑异常,case:{}", Throwables.getStackTraceAsString(be));
            serviceResult.setError(be.getCode(), be.getMessage());
            return serviceResult;
        } catch (Exception e) {
            IfpLogger.error("addEnterpriseUserInfo", "执行添加企业员工用户异常,case:{}", Throwables.getStackTraceAsString(e));
            serviceResult.setError(ErrorMessageConstant.ECUC0000_CODE, ErrorMessageConstant.ECUC0000_MESSAGE);
            return serviceResult;
        }
        return serviceResult;
    }

    /**
     * 分页查询角色关系
     * 
     * @param queryUserRoleRelationReq
     * @return
     */
    @POST
    @Path("query-user-role-relation-list")
    @ApiOperation(value = "企业员工角色关系分页查询", notes = "企业员工角色关系分页查询")
    @Override
    public ServiceResult<List<UserRoleRelationDto>>
        queryUserRoleRelationList(QueryUserRoleRelationReq queryUserRoleRelationReq) {
        ServiceResult<List<UserRoleRelationDto>> serviceResult = new ServiceResult<>();
        try {
            serviceResult.setResult(userRoleRelationModel.queryUserRoleRelationList(queryUserRoleRelationReq));
        } catch (BusinessException be) {
            IfpLogger.error("addEnterpriseUserInfo", "业务逻辑异常,case:{}", Throwables.getStackTraceAsString(be));
            serviceResult.setError(be.getCode(), be.getMessage());
            return serviceResult;
        } catch (Exception e) {
            IfpLogger.error("addEnterpriseUserInfo", "执行添加企业员工用户异常,case:{}", Throwables.getStackTraceAsString(e));
            serviceResult.setError(ErrorMessageConstant.ECUC0000_CODE, ErrorMessageConstant.ECUC0000_MESSAGE);
            return serviceResult;
        }
        return serviceResult;
    }

    /**
     * 查询角色关系
     *
     * @param queryUserRoleRelationListReq
     * @return
     */
    @POST
    @ApiOperation(value = "企业员工角色关系查询", notes = "企业员工角色关系查询")
    @Path("query-user-role-relation-info")
    @Override
    public ServiceResult<List<UserRoleRelationDto>>
        queryUserRoleRelationInfo(QueryUserRoleRelationListReq queryUserRoleRelationListReq) {
        ServiceResult<List<UserRoleRelationDto>> serviceResultList = new ServiceResult<>();
        try {
            serviceResultList.setResult(userRoleRelationModel.queryUserRoleRelationInfo(queryUserRoleRelationListReq));
        } catch (BusinessException be) {
            IfpLogger.error("addEnterpriseUserInfo", "业务逻辑异常,case:{}", Throwables.getStackTraceAsString(be));
            serviceResultList.setError(be.getCode(), be.getMessage());
            return serviceResultList;
        } catch (Exception e) {
            IfpLogger.error("addEnterpriseUserInfo", "执行添加企业员工用户异常,case:{}", Throwables.getStackTraceAsString(e));
            serviceResultList.setError(ErrorMessageConstant.ECUC0000_CODE, ErrorMessageConstant.ECUC0000_MESSAGE);
            return serviceResultList;
        }
        return serviceResultList;
    }

    /**
     * 查询港内员工组织结构
     *
     * @return
     */
    @POST
    @ApiOperation(value = "查询港内员工组织结构入口-内管使用", notes = "查询港内员工组织结构入口-内管使用")
    @Path("query-organizational-structure-list")
    @Override
    public ServiceResult<List<QueryOrganizationalStructureDto>> queryOrganizationalStructureList(BaseReqObj requestObject) {
        ServiceResult<List<QueryOrganizationalStructureDto>> serviceResultList = new ServiceResult<>();
        try {
            serviceResultList.setResult(userRoleRelationModel.queryOrganizationalStructureList());
        } catch (BusinessException be) {
            IfpLogger.error("addEnterpriseUserInfo", "业务逻辑异常,case:{}", Throwables.getStackTraceAsString(be));
            serviceResultList.setError(be.getCode(), be.getMessage());
            return serviceResultList;
        } catch (Exception e) {
            IfpLogger.error("addEnterpriseUserInfo", "执行添加企业员工用户异常,case:{}", Throwables.getStackTraceAsString(e));
            serviceResultList.setError(ErrorMessageConstant.ECUC0000_CODE, ErrorMessageConstant.ECUC0000_MESSAGE);
            return serviceResultList;
        }
        return serviceResultList;
    }

    /**
     * 查询企业组织结构
     *
     * @return
     */
    @POST
    @ApiOperation(value = "查询企业组织结构入口-内管使用", notes = "查询企业组织结构入口-内管使用")
    @Path("query-corporate-organization-role")
    @Override
    public ServiceResult<List<QueryCorporateOrganizationRoleDto>> queryCorporateOrganizationRole(BaseReqObj requestObject) {
        ServiceResult<List<QueryCorporateOrganizationRoleDto>> serviceResultList = new ServiceResult<>();
        try {
            serviceResultList.setResult(userRoleRelationModel.queryCorporateOrganizationRole());
        } catch (Exception e) {
            IfpLogger.error("addEnterpriseUserInfo", "执行添加企业员工用户异常,case:{}", Throwables.getStackTraceAsString(e));
            serviceResultList.setError(ErrorMessageConstant.ECUC0000_CODE, ErrorMessageConstant.ECUC0000_MESSAGE);
            return serviceResultList;
        }
        return serviceResultList;
    }

    /**
     * 查询港内员工结构入口
     *
     * @return
     */
    @POST
    @ApiOperation(value = "查询港内员工结构入口-内管使用", notes = "查询港内员工入口-内管使用")
    @Path("query-port-user-info-list")
    @Override
    public ServiceResult<List<QueryPortUserInfoDto>> queryPortUserInfoList(BaseReqObj requestObject) {
        ServiceResult<List<QueryPortUserInfoDto>> listServiceResult = new ServiceResult<>();
        try {
            listServiceResult.setResult(userRoleRelationModel.queryPortUserInfoList());
        } catch (Exception e) {
            IfpLogger.error("addEnterpriseUserInfo", "执行添加企业员工用户异常,case:{}", Throwables.getStackTraceAsString(e));
            listServiceResult.setError(ErrorMessageConstant.ECUC0000_CODE, ErrorMessageConstant.ECUC0000_MESSAGE);
            return listServiceResult;
        }
        return listServiceResult;
    }

    /**
     * 查询企业员工入口
     *
     * @return
     */
    @POST
    @ApiOperation(value = "查询企业员工入口-内管使用", notes = "查询企业员工入口-内管使用")
    @Path("query-enterprise-user-info")
    @Override
    public ServiceResult<List<QueryEnterpriseUserInfoDto>> queryEnterpriseUserInfo(BaseReqObj requestObject) {
        ServiceResult<List<QueryEnterpriseUserInfoDto>> listServiceResult = new ServiceResult<>();
        try {
            listServiceResult.setResult(userRoleRelationModel.queryEnterpriseUserInfo());
        } catch (Exception e) {
            IfpLogger.error("addEnterpriseUserInfo", "执行添加企业员工用户异常,case:{}", Throwables.getStackTraceAsString(e));
            listServiceResult.setError(ErrorMessageConstant.ECUC0000_CODE, ErrorMessageConstant.ECUC0000_MESSAGE);
            return listServiceResult;
        }
        return listServiceResult;
    }
}
